/**
 * Created by Jason on 2016/8/22.
 */

//timer-picker
var timePicker = (function () {
    return {
        showMonth: function (id) {
            timePicker.show(id, "month", "yyyy-mm-dd");
        },
        showDay: function (id) {
            timePicker.show(id, "day", "yyyy-mm-dd HH");
        },
        showHourToSecond: function (id) {
            $(id).datetimepicker({
                maxView: "day",
                minView: "hour",
                format: "HH:ii",
                language: 'zh-CN',
                autoclose: true,
                startView: 1,
                minuteStep: 1,
            });
        },
        show: function (id, minView, format) {
            $(id).datetimepicker({
                minView: minView,
                format: format,
                language: 'zh-CN',
                autoclose: true,
                todayBtn: true,
            });
        },
        howOption: function (id, minView, maxView, startView, format) {
            $(id).datetimepicker({
                minView: minView,
                maxView: maxView,
                startView: startView,
                format: format,
                language: 'zh-CN',
                autoclose: true,
                todayBtn: true,
            });
        }
    };
})();

var cookie = (function () {

    return {

        getCookie: function (name) {
            var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
            if (arr = document.cookie.match(reg))
                return unescape(arr[2]);
            else
                return null;
        },
        setCookie: function (name, value) {
            var Days = 30;
            var exp = new Date();
            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
            document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
        },
        delCookie: function (name) {
            var exp = new Date();
            exp.setTime(exp.getTime() - 1);
            var cval = getCookie(name);
            if (cval != null)
                document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
        }

    }
})();


function getJSONP(url, para, cb) {
    var callback = cb;
    $.ajax({
        async: false,
        url: url,
        type: "GET",
        dataType: 'jsonp',
        jsonp: 'callback',
        jsonpCallback: "callback",
        data: para,
        timeout: 5000,

        success: function (json) {
            //客户端jquery预先定义好的callback函数,成功获取跨域服务器上的json数据后,会动态执行这个callback函数
            callback(json);
        }
        ,
        complete: function (XMLHttpRequest, textStatus) {
            console.log("complete");
        }

    });

}


/*扩展*/
Number.prototype.fillZero = function (size) {
    var len = ('' + this).length;
    return (Array(
        size > len ? size - len + 1 || 0 : 0
    ).join(0) + this);
}
String.prototype.trim = function () {
    return this.replace(/[ ]/g, "");
}